package cn.tedu.zhxy.controller;


import cn.tedu.zhxy.entity.Student;
import cn.tedu.zhxy.service.StudentService;
import cn.tedu.zhxy.util.MD5;
import cn.tedu.zhxy.util.Result;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.UUID;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ${author}
 * @since 2022-07-20
 */
@RestController
@RequestMapping("/sms/studentController")
public class StudentController {
    @Autowired
    private StudentService studentService;

    @DeleteMapping("delStudentById")
    public  Result  delStudentById(@RequestBody List<Integer> ids){
        studentService.removeByIds(ids);
        return   Result.ok();
    }

    @PostMapping("addOrUpdateStudent")
    public  Result  addOrUpdateStudent(@RequestBody Student student){
        String encrypt = MD5.encrypt(student.getPassword());
        student.setPassword(encrypt);
        studentService.saveOrUpdate(student);
        return   Result.ok();
    }
    @GetMapping("getStudentByOpr/{page}/{limit}")
    public Result  getStudentByOpr(@PathVariable Long  page, @PathVariable Long limit, Student student){
        Page<Student> pageParam = new Page<>(page,limit);
        IPage<Student> list = studentService.selectList(pageParam,student);
        return   Result.ok(list);
    }

}

